package com.new_wear.project.system.rules.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.rules.domain.CstUserIntegralRules;
import com.new_wear.project.system.rules.service.ICstUserIntegralRulesService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 用户 - 等级积分规则Controller
 * 
 * @author new_wear
 * @date 2020-01-07
 */
@Controller
@RequestMapping("/system/rules")
public class CstUserIntegralRulesController extends BaseController
{
    private String prefix = "system/rules";

    @Autowired
    private ICstUserIntegralRulesService cstUserIntegralRulesService;

    @RequiresPermissions("system:rules:view")
    @GetMapping()
    public String rules()
    {
        return prefix + "/rules";
    }

    /**
     * 查询用户 - 等级积分规则列表
     */
    @RequiresPermissions("system:rules:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CstUserIntegralRules cstUserIntegralRules)
    {
        startPage();
        List<CstUserIntegralRules> list = cstUserIntegralRulesService.selectCstUserIntegralRulesList(cstUserIntegralRules);
        return getDataTable(list);
    }

    /**
     * 导出用户 - 等级积分规则列表
     */
    @RequiresPermissions("system:rules:export")
    @Log(title = "用户 - 等级积分规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CstUserIntegralRules cstUserIntegralRules)
    {
        List<CstUserIntegralRules> list = cstUserIntegralRulesService.selectCstUserIntegralRulesList(cstUserIntegralRules);
        ExcelUtil<CstUserIntegralRules> util = new ExcelUtil<CstUserIntegralRules>(CstUserIntegralRules.class);
        return util.exportExcel(list, "rules");
    }

    /**
     * 新增用户 - 等级积分规则
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户 - 等级积分规则
     */
    @RequiresPermissions("system:rules:add")
    @Log(title = "用户 - 等级积分规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CstUserIntegralRules cstUserIntegralRules)
    {
        return toAjax(cstUserIntegralRulesService.insertCstUserIntegralRules(cstUserIntegralRules));
    }

    /**
     * 修改用户 - 等级积分规则
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CstUserIntegralRules cstUserIntegralRules = cstUserIntegralRulesService.selectCstUserIntegralRulesById(id);
        mmap.put("cstUserIntegralRules", cstUserIntegralRules);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户 - 等级积分规则
     */
    @RequiresPermissions("system:rules:edit")
    @Log(title = "用户 - 等级积分规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CstUserIntegralRules cstUserIntegralRules)
    {
        return toAjax(cstUserIntegralRulesService.updateCstUserIntegralRules(cstUserIntegralRules));
    }

    /**
     * 删除用户 - 等级积分规则
     */
    @RequiresPermissions("system:rules:remove")
    @Log(title = "用户 - 等级积分规则", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cstUserIntegralRulesService.deleteCstUserIntegralRulesByIds(ids));
    }
}
